#!/bin/bash

# Let runit capture all script error messages
exec 2>&1

<%= render("make_metrics_rundir.erb") %>
<%= render("mount_point_check.erb") %>

exec chpst -P -u <%= @options[:user] %>:<%= @options[:groupname] %> -U <%= @options[:user] %>:<%= @options[:groupname] %> \
  /usr/bin/env \
    current_pidfile=<%= node['gitlab'][@options[:service]]['pidfile'] %> \
    rails_app=<%= @options[:rails_app] %> \
    user=<%= @options[:user] %> \
    group=<%= @options[:groupname] %> \
    environment=<%= node['gitlab'][@options[:rails_app]]['environment'] %> \
    unicorn_rb=<%= @options[:unicorn_rb] %> \
    prometheus_multiproc_dir="${prometheus_run_dir}" \
    /opt/gitlab/embedded/bin/gitlab-unicorn-wrapper
